package com.ludomancy.gamelib.entity;

import com.ludomancy.gamelib.MathHelper;

public class EntityRadiusFilter implements EntityFilter
{
	private Class clazz;
	private int radius;
	private Entity center;

	public EntityRadiusFilter(Entity center, int radius)
	{
		this(center, radius, null);
	}
	
	public EntityRadiusFilter(Entity center, int radius, Class clazz)
	{
		this.clazz = clazz;
		this.center = center;
		this.radius = radius;
	}
	
	public boolean accepts(Entity e)
	{
		int otherRadius = Math.max(e.getWidth(), e.getHeight());
		if(e != center && MathHelper.dist(e.pos.x, e.pos.y, center.pos.x, center.pos.y) <= (radius - otherRadius))
		{
			if(clazz == null || e.getClass() == clazz)
			{
				return true;
			}
		}
		return false;
	}
}